import 'package:eplorex/utils/ColorUtil.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../../../utils/DateUtil.dart';
import 'ButtonWidget.dart';


class ProfileBirthdayPicker extends StatefulWidget {
  const ProfileBirthdayPicker({
    Key? key,
    required this.confirmPressed,
  }) : super(key: key);

  final Function(String date) confirmPressed;

  @override
  State<ProfileBirthdayPicker> createState() => _ProfileBirthdayPickerState();
}

class _ProfileBirthdayPickerState extends State<ProfileBirthdayPicker> {
  String _datePickerDate = "";

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 256.0,
      color: Colors.white,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          _buildButtonRow(context),
          Expanded(
            child: CupertinoDatePicker(
              dateOrder: DatePickerDateOrder.ymd,
              mode: CupertinoDatePickerMode.date,
              initialDateTime: DateTime.now(),
              onDateTimeChanged: (date) {
                print('onDateTimeChanged - $date');
                String dateString = DateUtil.formatDate(date, format: "yyyy-MM-dd");
                _datePickerDate = dateString;
              },
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildButtonRow(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        ButtonWidget(
          width: 80,
          height: 50,
          onPressed: () {
            Navigator.pop(context);
          },
          highlightedColor: ColorUtil.hexColor(0xf7f7f7),
          bgColor: ColorUtil.hexColor(0xffffff),
          bgHighlightedColor: ColorUtil.hexColor(0xf7f7f7),
          enabled: true,
          bgDisableColor: Colors.grey,
          borderRadius: 8.0,
          child: Text(
            "取消",
            textAlign: TextAlign.center,
            softWrap: true,
            style: TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.w500,
              fontStyle: FontStyle.normal,
              color: ColorUtil.hexColor(0xA1A1A1),
              decoration: TextDecoration.none,
            ),
          ),
        ),
        ButtonWidget(
          width: 80,
          height: 50,
          onPressed: () {
            widget.confirmPressed(_datePickerDate);
            Navigator.pop(context);
          },
          highlightedColor: ColorUtil.hexColor(0xf7f7f7),
          bgColor: ColorUtil.hexColor(0xffffff),
          bgHighlightedColor: ColorUtil.hexColor(0xf7f7f7),
          enabled: true,
          bgDisableColor: Colors.grey,
          borderRadius: 8.0,
          child: Text(
            "确定",
            textAlign: TextAlign.center,
            softWrap: true,
            style: TextStyle(
              fontSize: 16,
              fontWeight: FontWeight.w400,
              fontStyle: FontStyle.normal,
              color: ColorUtil.hexColor(0x338FFF),
              decoration: TextDecoration.none,
            ),
          ),
        ),
      ],
    );
  }
}
